class Solution:
    @staticmethod
    def permute(nums: list[int]) -> list[list[int]]:
        numsSize = len(nums)
        visited = [False for _ in range(numsSize)]
        temp = []
        res = []

        def dfs(n):
            if n == numsSize:
                res.append(temp.copy())
                return

            for j in range(numsSize):
                if visited[j]:
                    continue

                visited[j] = True
                temp.append(nums[j])
                dfs(n + 1)
                visited[j] = False
                temp.pop(-1)

        dfs(0)
        return res
